const router = require('koa-router')()
const { loginRedirect } = require('../middlewares/loginChecks')
const { loginCheck } = require('../middlewares/loginChecks')

router.get('/', loginRedirect, async (ctx, next) => {
    await ctx.render('index', {
        title: 'Hello Koa 2!',
    })
})

router.get('/test', async (ctx, next) => {
    throw new Error('123')
    await ctx.render('index', {
        title: 'Hello Koa 2!',
    })
})



router.get('/string', async (ctx, next) => {
    ctx.body = 'koa2 string'
})

router.get('/json', loginCheck, async (ctx, next) => {
    // ctx.session.viewNum = (ctx.session.viewNum || 0) + 1
    // console.log('---ctx.session.viewNum--', ctx.session.viewNum, '---ctx.session.viewNum || 0--', ctx.session.viewNum || 0);
    ctx.body = {
        title: 'koa2 json',
    // viewNum: ctx.session.viewNum
    }
})

module.exports = router
